package com.ruoyi.core.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.core.service.StoreDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.core.domain.store.StoreDetail;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商户详情信息Controller
 * 
 * @author Sxz
 * @date 2025-08-06
 */
@RestController
@RequestMapping("/storeDetail")
public class StoreDetailController extends BaseController
{
    @Autowired
    private StoreDetailService storeDetailService;

    /**
     * 查询商户详情信息列表
     */
    @RequiresPermissions("core:storeDetail:list")
    @GetMapping("/list")
    public TableDataInfo list(StoreDetail storeDetail) {
        startPage();
        QueryWrapper<StoreDetail> wrapper = new QueryWrapper<>(storeDetail);
        List<StoreDetail> list = storeDetailService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 导出商户详情信息列表
     */
    @RequiresPermissions("core:storeDetail:export")
    @Log(title = "商户详情信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StoreDetail storeDetail) {
        QueryWrapper<StoreDetail> wrapper = new QueryWrapper<>(storeDetail);
        List<StoreDetail> list = storeDetailService.list(wrapper);
        ExcelUtil<StoreDetail> util = new ExcelUtil<>(StoreDetail.class);
        util.exportExcel(response, list, "商户详情信息数据");
    }

    /**
     * 获取商户详情信息详细信息
     */
    @RequiresPermissions("core:storeDetail:query")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(storeDetailService.getById(id));
    }

    /**
     * 新增商户详情信息
     */
    @RequiresPermissions("core:storeDetail:add")
    @Log(title = "商户详情信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreDetail storeDetail) {
        return toAjax(storeDetailService.save(storeDetail));
    }

    /**
     * 修改商户详情信息
     */
    @RequiresPermissions("core:storeDetail:edit")
    @Log(title = "商户详情信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreDetail storeDetail) {
        return toAjax(storeDetailService.updateById(storeDetail));
    }

    /**
     * 删除商户详情信息（逻辑删除生效）
     */
    @RequiresPermissions("core:storeDetail:remove")
    @Log(title = "商户详情信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(storeDetailService.removeByIds(new ArrayList<>(Arrays.asList(ids))));

    }
}